﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Utils;
using TechnicalIndicators.Points;
using TechnicalIndicators.DateBaseBased;

namespace TechnicalIndicatorsIntegrationTests
{
	[TestClass]
	public class RSIIntegrationTest
	{
		[TestMethod]
		public void MainTestAllInOne()
		{
			DateTime startDate = DateTime.Parse("01/01/2012 09:00:00");
			ObservableCollection2<DatedSeriePoint> source = new ObservableCollection2<DatedSeriePoint>();

			RSI generator = new RSI();

			generator.Source = new ReadWriteLockedObservableCollection<DatedSeriePoint>(source, new TimeSpan(0, 0, 1));
			generator.Configure(14, TechnicalIndicators.DateBased.RSIMode.Standard);

			source.Add(new DatedSeriePoint(startDate, 44.34m));
			source.Add(new DatedSeriePoint(startDate.AddDays(1), 44.09m));
			source.Add(new DatedSeriePoint(startDate.AddDays(2), 44.15m));
			source.Add(new DatedSeriePoint(startDate.AddDays(3), 43.61m));
			source.Add(new DatedSeriePoint(startDate.AddDays(4), 44.33m));
			source.Add(new DatedSeriePoint(startDate.AddDays(5), 44.83m));
			source.Add(new DatedSeriePoint(startDate.AddDays(6), 45.10m));
			source.Add(new DatedSeriePoint(startDate.AddDays(7), 45.42m));
			source.Add(new DatedSeriePoint(startDate.AddDays(8), 45.84m));
			source.Add(new DatedSeriePoint(startDate.AddDays(9), 46.08m));
			source.Add(new DatedSeriePoint(startDate.AddDays(10), 45.89m));
			source.Add(new DatedSeriePoint(startDate.AddDays(11), 46.03m));
			source.Add(new DatedSeriePoint(startDate.AddDays(12), 45.61m));
			source.Add(new DatedSeriePoint(startDate.AddDays(13), 46.28m));
			source.Add(new DatedSeriePoint(startDate.AddDays(14), 46.28m));
			source.Add(new DatedSeriePoint(startDate.AddDays(15), 46.00m));
			source.Add(new DatedSeriePoint(startDate.AddDays(16), 46.03m));
			source.Add(new DatedSeriePoint(startDate.AddDays(17), 46.41m));
			source.Add(new DatedSeriePoint(startDate.AddDays(18), 46.22m));
			source.Add(new DatedSeriePoint(startDate.AddDays(19), 45.64m));
			source.Add(new DatedSeriePoint(startDate.AddDays(20), 46.21m));
			source.Add(new DatedSeriePoint(startDate.AddDays(21), 46.25m));
			source.Add(new DatedSeriePoint(startDate.AddDays(22), 45.71m));
			source.Add(new DatedSeriePoint(startDate.AddDays(23), 46.45m));
			source.Add(new DatedSeriePoint(startDate.AddDays(24), 45.78m));
			source.Add(new DatedSeriePoint(startDate.AddDays(25), 45.35m));
			source.Add(new DatedSeriePoint(startDate.AddDays(26), 44.03m));
			source.Add(new DatedSeriePoint(startDate.AddDays(27), 44.18m));
			source.Add(new DatedSeriePoint(startDate.AddDays(28), 44.22m));
			source.Add(new DatedSeriePoint(startDate.AddDays(29), 44.57m));
			source.Add(new DatedSeriePoint(startDate.AddDays(30), 43.42m));
			source.Add(new DatedSeriePoint(startDate.AddDays(31), 42.66m));
			source.Add(new DatedSeriePoint(startDate.AddDays(32), 43.13m));

			generator.Start();

			var generatedSerie = generator.Serie.GetReadLock();

			Assert.AreEqual(19, generatedSerie.Count);
			Assert.AreEqual(70.46m, Math.Round(generatedSerie[0].Y, 2));
			Assert.AreEqual(66.25m, Math.Round(generatedSerie[1].Y, 2));
			Assert.AreEqual(66.48m, Math.Round(generatedSerie[2].Y, 2));
			Assert.AreEqual(69.35m, Math.Round(generatedSerie[3].Y, 2));
			Assert.AreEqual(66.29m, Math.Round(generatedSerie[4].Y, 2));
			Assert.AreEqual(57.92m, Math.Round(generatedSerie[5].Y, 2));
			Assert.AreEqual(62.88m, Math.Round(generatedSerie[6].Y, 2));
			Assert.AreEqual(63.21m, Math.Round(generatedSerie[7].Y, 2));
			Assert.AreEqual(56.01m, Math.Round(generatedSerie[8].Y, 2));
			Assert.AreEqual(62.34m, Math.Round(generatedSerie[9].Y, 2));
			Assert.AreEqual(54.67m, Math.Round(generatedSerie[10].Y, 2));
			Assert.AreEqual(50.39m, Math.Round(generatedSerie[11].Y, 2));
			Assert.AreEqual(40.02m, Math.Round(generatedSerie[12].Y, 2));
			Assert.AreEqual(41.49m, Math.Round(generatedSerie[13].Y, 2));
			Assert.AreEqual(41.90m, Math.Round(generatedSerie[14].Y, 2));
			Assert.AreEqual(45.50m, Math.Round(generatedSerie[15].Y, 2));
			Assert.AreEqual(37.32m, Math.Round(generatedSerie[16].Y, 2));
			Assert.AreEqual(33.09m, Math.Round(generatedSerie[17].Y, 2));
			Assert.AreEqual(37.79m, Math.Round(generatedSerie[18].Y, 2));

		}
	}
}
